import React from 'react';
import {BrowserRouter as Router,Route,Switch,Redirect} from 'react-router-dom';
import Major from './Major'
import {useSelector,useDispatch,connect} from 'react-redux'
import Login from './routes/Login'

const ContentMajor = () => {
  const login = useSelector(state=> state.login.islogin)
  const PrivateRoute = ({component:Com,...rest}) => {
    return <Route {...rest} render={({location}) => {
        const userInfo = login;
        if(userInfo){
            return Com
        }else{
            //从哪来到哪去
            return <Redirect to={
                {
                    pathname:'/login',
                    state:location
                }
            }/>
        }
    }
    }/>
}

  return (
    <div>
      <Switch>
        <PrivateRoute exact path="/" component={<Major prop='user'/>}/>
        <PrivateRoute path="/schoolrecruit" component={<Major prop='schoolrecruit'/>}/>
        <PrivateRoute path="/checkmes" component={<Major prop='checkmes'/>}/>
        <PrivateRoute path="/word" component={<Major prop='word'/>}/>
        <PrivateRoute path="/wordhistory" component={<Major prop='wordhistory'/>}/>
        <PrivateRoute path="/schoolscore" component={<Major prop='score'/>}/>
        <PrivateRoute path="/schoolnumber" component={<Major prop='number'/>}/>
        <PrivateRoute path="/examknowledge" component={<Major prop='knowledge'/>}/>
        <PrivateRoute path="/exampolicy" component={<Major prop='policy'/>}/>
        <PrivateRoute path="/examchoose" component={<Major prop='choose'/>}/>
        <PrivateRoute path="/examguide" component={<Major prop='guide'/>}/>
        <PrivateRoute path="/book" component={<Major prop='book'/>}/>
        <PrivateRoute path="/circle" component={<Major prop='circle'/>}/>
        <PrivateRoute path="/usercoms" component={<Major prop='usercoms'/>}/>
        <PrivateRoute path="/usermessage" component={<Major prop='message'/>}/>
        <PrivateRoute path="/usercompose" component={<Major prop='compose'/>}/>
        <PrivateRoute path="/userlike" component={<Major prop='like'/>}/>
        <PrivateRoute path="/userexamhistory" component={<Major prop='examhistory'/>}/>
        <PrivateRoute path="/userstudyhistory" component={<Major prop='studyhistory'/>}/>
        <PrivateRoute path="/admin" component={<Major prop='admin'/>}/>
        <Route path="/login" component={Login} />
    </Switch>
    </div>
    
      
    
      
  )
}

export default connect()(ContentMajor);
